package com.jgk.gwt.recipes.contacts.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class JgkContacts implements EntryPoint {
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		// String url = GWT.getModuleBaseURL()+"person.js";
		// url="person.js";
		// // url="http://localhost:8080/simpleweb/person.jsp";
		// url="http://127.0.0.1:8080/simpleweb/person.jsp";
		// //url="http://localhost:8080/simpleweb/person.json";
		// RootPanel.get().add( new Label("HELLO"));
		// RequestBuilder blder= new RequestBuilder(RequestBuilder.GET,url);
		// try {
		// blder.sendRequest(null, new RequestCallback() {
		//
		// @Override
		// public void onResponseReceived(Request request, Response response) {
		// // TODO Auto-generated method stub
		// Window.alert("BACK with data..."+response.getStatusCode());
		// //Window.alert(response.getText()+"\nHERE IN GARAGE\n"+response.getHeadersAsString());
		// JSONObject person = (JSONObject)
		// JSONParser.parse(response.getText());
		// String firstName = ((JSONString)
		// person.get("firstName")).stringValue();
		// Window.alert("firstName: " + firstName);
		// }
		//
		// @Override
		// public void onError(Request request, Throwable exception) {
		// // TODO Auto-generated method stub
		// Window.alert("EROR");
		// }
		// });
		// } catch (RequestException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// Window.alert("PROBLEM");
		// } catch (RuntimeException e) {
		// e.printStackTrace();
		// Window.alert("Exception: " + e);
		// }
		//
		ContactsServiceAsync rpcService = GWT.create(ContactsService.class);
		SimpleEventBus eventBus = new SimpleEventBus();
		AppController appViewer = new AppController(rpcService, eventBus);
		appViewer.go(RootPanel.get());
		
//		supplemental();
	}

	private void supplemental() {
		final Label label = new Label("JED");
		RootPanel.get().add(new Label("BEFORE"));
		RootPanel.get().add(label);
		RootPanel.get().add(new Label("AFTER"));
		Timer t = new Timer() {
			@Override
			public void run() {
				// Window.alert("Nifty, eh?");
				label.setVisible(false);
			}
		};
		// Schedule the timer to run once in 5 seconds.
		t.schedule(5000);
	}

}
